<?php
namespace Plu\qdh\Models\App;

use Phalcon\Mvc\Model;

class QrCode extends Model
{

    // CREATE TABLE `qrcode` (
    //     `id` int(11) NOT NULL,
    //     `name` varchar(45) NOT NULL COMMENT '描述',
    //     `url` varchar(45) NOT NULL COMMENT '跳转地址',
    //     `imgUrl` varchar(200) NOT NULL COMMENT '二维码地址',
    //     `createTime` datetime NOT NULL COMMENT '创建时间',
    //     PRIMARY KEY (`id`)
    //   ) ENGINE=InnoDB DEFAULT CHARSET=utf8

    public function initialize() {
        $this->setConnectionService('db.qdh');
        $this->allowEmptyStringValues([]);
    }


	public function getSource() {
		return "qrcode";
    }

    static public function getItems($limit, $offset) {
        $count = self::count();
        $where = [
            'order'  => 'createTime desc',
            'limit'  => $limit,
            'offset' => $offset
        ];
        $items = self::find($where);
        if ($items) {
            $items = $items->toArray();
            return [$count, $items];
        }
        return [0, []];
    }

    static public function getAllItems() {
        $where = [
            'order'  => 'createTime desc'
        ];
        $items = self::find($where);
        if ($items) {
            $items = $items->toArray();
            return $items;
        }
    }

    static public function getItemByShopName($shopName) {
        $where = [
            'conditions' => 'name = :shopName:',
            'bind' => [
                'shopName' => $shopName
            ]
        ];
        $item = self::findFirst($where);
        return $item;
    }



}